package com.jianrui.msgvision.view.widget

import android.content.Context
import android.content.DialogInterface
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.hunktimes.wholesale.R
import kotlinx.android.synthetic.main.bot_options.*

class BotOptionsDialog : BottomSheetDialog {
    constructor(context: Context) : this(context, R.style.WholeSaleDialogTheme)
    constructor(context: Context, theme: Int) : super(context, theme)
    constructor(
        context: Context,
        cancelable: Boolean,
        cancelListener: DialogInterface.OnCancelListener?
    ) : super(context, cancelable, cancelListener)

    var op1Listener: DialogInterface.OnClickListener? = null
    var op2Listener: DialogInterface.OnClickListener? = null
    var op3Listener: DialogInterface.OnClickListener? = null

    var op1Text: String? = null
    var op2Text: String? = null
    var cancelText: String? = null

    init {
        setContentView(R.layout.bot_options)
    }

    override fun onStart() {
        super.onStart()
        option_1_tv.setOnClickListener {
            op1Listener?.onClick(this, it.id)
        }
        option_2_tv.setOnClickListener {
            op2Listener?.onClick(this, it.id)
        }

        cancel_tv.setOnClickListener {
            op3Listener?.onClick(this, it.id)
        }
        op1Text?.let {
            option_1_tv.text = it
        }
        op2Text?.let {
            option_2_tv.text = it
        }
        cancelText?.let {
            cancel_tv.text = it
        }
    }

    constructor(builder: Builder) : this(builder.context) {
        this.op1Listener = builder.op1Listener
        this.op2Listener = builder.op2Listener
        this.op3Listener = builder.op3Listener
        this.op1Text = builder.op1Text
        this.op2Text = builder.op2Text
        this.cancelText = builder.cancelText

    }

    class Builder {
        var op1Listener: DialogInterface.OnClickListener? = null
        var op2Listener: DialogInterface.OnClickListener? = null
        var op3Listener: DialogInterface.OnClickListener? = null
        var context: Context

        var op1Text: String? = null
        var op2Text: String? = null
        var cancelText: String? = null

        constructor(context: Context) {
            this.context = context
        }

        private fun create(): BotOptionsDialog = BotOptionsDialog(this)

        fun build(): BotOptionsDialog = create()
    }
}
